import {ADDCART} from './mutations-type.js'
export default {
      [ADDCART](state,value){
        state.cartSum = value
      },
      changeDelete(state){
        state.isDelete = !state.isDelete
      },
      deleteList(state,value){
        state.cartSum = value
      },
      pay(state,value){
        state.orderList = value
      },
      orderListEnd(state){
        state.orderListEnd = state.orderListEnd.concat(state.orderList)
      },
      //新添加地址
      addaddress(state,value){
        state.userAddress.map(item=>{
          if(value.isDefault){
            item.isDefault = false;
          }
        })
        state.userAddress.push(value)
      },
      //编辑地址
      editaddress(state,value){
        state.userAddress = state.userAddress.map(item=>{
          if(value.isDefault){
            item.isDefault = false;
          }
          return item.id === value.id ? value : item
        })
      },
      // 删除地址
      deleteAddress(state,value){
        state.userAddress = state.userAddress.filter(item=>{
          return !(item.id === value.id)
        })
        if(value.isDefault){
          state.userAddress[0] = true;
        }
      }
}